package goodroommate.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import goodroommate.dal.DatabaseSession;
import goodroommate.dao.ITypeDao;
import goodroommate.domain.Type;
import goodroommate.exception.DatabaseException;

public class TypeDao implements ITypeDao {

	@Override
	public ArrayList<Type> getAllTypes(DatabaseSession databaseSession) throws DatabaseException {
		String sql="SELECT * FROM types";
		ArrayList<Type>types=new ArrayList<>();
		try{
			ResultSet rSet=databaseSession.executeQuery(sql);
			while(rSet.next()){
				Type type=new Type();
				type.setTypeid(rSet.getLong("TypeID"));
				type.setDomitorycount(rSet.getInt("DomitoryCount"));
				type.setDomitorynoisy(rSet.getInt("DomitoryNoisy"));
				type.setDomitorylayer(rSet.getInt("DomitoryLayer"));
				type.setDomitoryyear(rSet.getInt("DomitoryYear"));
				types.add(type);			
			}
			return types;
		} catch (SQLException e) {
			throw new DatabaseException();
		}
	}

}
